package network.server;

import network.managers.ObserverManager;

public class ObserverPingThread implements Runnable {
    
    private static ObserverPingThread instance;
    private static Thread runThread;
    
    public static void init()
    {
        instance = new ObserverPingThread();
        runThread = new Thread(instance);
        runThread.start();
    }
    
    public static void shutdown()
    {
        instance.shouldContinue = false;
        
        try
        {
            runThread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
    }
    
    private boolean shouldContinue = true;
    
    private ObserverPingThread()
    {
        //NOOP
    }
    
    public void run()
    {
        
        ObserverManager.init();
        
        while (shouldContinue)
        {
            try
            {
                Thread.sleep(500);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            
            synchronized (ObserverManager.getInstance())
            {
                ObserverManager.getInstance().notify();
            }
            
        }
        
        ObserverManager.shutdown();
    }
    
}
